﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using FastColoredTextBoxNS;

namespace Appendage
{
    public partial class IDE : Form
    {
        TextStyle stringStyle;
        TextStyle numStyle;
        TextStyle operStyle;
        TextStyle commentStyle;

        public IDE()
        {
            InitializeComponent();

            stringStyle = make(Color.DarkRed, FontStyle.Regular);
            numStyle = make(Color.DarkGreen, FontStyle.Regular);
            operStyle = make(Color.Red, FontStyle.Regular);
            commentStyle = make(Color.Gray, FontStyle.Regular);
        }
        TextStyle make(Color color, FontStyle fstyle)
        {
            return new TextStyle(new SolidBrush(color), new SolidBrush(Color.Transparent), fstyle);
        }

        private void fctb_TextChanged(object sender, TextChangedEventArgs e)
        {
            // does RegexOptions.Singleline even do anything?
            e.ChangedRange.ClearStyle(stringStyle, numStyle, operStyle, commentStyle);
            e.ChangedRange.SetStyle(stringStyle, @"""([^""]|(\""))*""", RegexOptions.Singleline);
            e.ChangedRange.SetStyle(numStyle, @"\b\d+(\.\d*)?\b");
            e.ChangedRange.SetStyle(operStyle, @"\b[`!@#$%^&*()-+=|<>,/?:;]+\b");
            e.ChangedRange.SetStyle(commentStyle, @"~[^\n]*");
            e.ChangedRange.SetStyle(commentStyle, @"~\[.*\]~", RegexOptions.Singleline);
        }

        private void runClicked(object sender, EventArgs e)
        {
            string program = fctb.Text;
            string path = Path.GetTempFileName();
            File.WriteAllText(path, program);
            const string CONCAT_EXE = @"C:\Users\Grant\Desktop\Concat\Concat\bin\Debug\concat.exe";
            string args = "\"" + path + "\" -repl";
            Process concat = new Process();
            Process.Start(CONCAT_EXE, args);
        }
    }
}
